<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html >
<html>
<head>
	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
	<script type="text/javascript" src="<%=contextPath %>/static/kindeditor/kindeditor-all-min.js"></script>
    <script charset="utf-8" src="<%=contextPath %>/static/kindeditor/lang/zh-CN.js"></script>
</head>
<body style="background-color: white;" class="gray-bg">
	<div class="ibox-content">
		<form class="form-horizontal m-t " id="signupForm" method="post"
			enctype="multipart/form-data">
					<div class="form-group">
				<label class="col-sm-3 control-label">会议室名称：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="meetingRoom" name="meetingRoom" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">申请人：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="user1Name" onclick="openTree('user',1);" readonly="readonly" placeholder="请选择申请人"/>
					<input type="hidden" class="form-control" id="user1Id" name="proposer"/>
					<p class="help-block" style="color: red;">*必填项，请选择一个系统用户</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">会议发起人：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="user2Name" onclick="openTree('user',2);" readonly="readonly" placeholder="请选择会议发起人"/>
					<input type="hidden" class="form-control" id="user2Id" name="initiator"/>
					<p class="help-block" style="color: red;">*必填项，请选择一个系统用户</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">参会人员：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="user3Name" onclick="openTree('user',3);" readonly="readonly" placeholder="请选择参会人员"/>
					<input type="hidden" class="form-control" id="user3Id" name="conferees"/>
					<p class="help-block" style="color: red;">*必填项，请选择系统用户</p>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">开始时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control datetime" id="startDate" name="startDate" readonly="readonly"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">结束时间：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control datetime" id="endDate" name="endDate" readonly="readonly"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">会议事项：</label>
				<div class="col-sm-10" >
				  <textarea rows="3" cols="3" class="form-control" style="width: 100%" id="agenda" name="agenda"></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input type="text" class="form-control" id="remark" name="remark" />
				</div>
			</div>
			<div class="form-group" style="text-align: center;">
				<div class="col-sm-12">
					<button class="btn btn-primary" type="button" id="sub">提交</button>
				</div>
			</div>
		</form>
	</div>


	<script>
	KindEditor.ready(function(K){
		K.create('textarea[name="agenda"]', {
		themeType: 'simple',
		resizeType: 1,
		allowFileManager: true,
		items : [
			'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
			'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
			'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
		afterBlur: function(){this.sync();}
		});
	});
    $(function () {
    	//日期插件
    	$('#startDate').datetimepicker({
            format: 'yyyy-mm-dd hh:ii:ss',
	        autoclose: true,
	        todayBtn: true,
	        startView: 'day',
	        minView:'0',
	        maxView:'decade',
	        minuteStep:1,
	        language:  'zh-CN',
	        initialDate : new Date()
	    });
        $('#startDate').datetimepicker('setDate',(new Date()));//赋值，当前日期
        $('#endDate').datetimepicker({
            format: 'yyyy-mm-dd hh:ii:ss',
	        autoclose: true,
	        todayBtn: true,
	        startView: 'day',
	        minView:'0',
	        maxView:'decade',
	        minuteStep:1,
	        language:  'zh-CN',
	        startDate: new Date()
	    });
        $('#endDate').datetimepicker('setDate',(new Date()));//赋值，当前日期
        //触发点击事件
        $("#sub").click(function () {
        	//批量验证表单非空
			//调用方式
        	var arr=new Array(
        	  new Array('meetingRoom','会议室名称未填写!'),
        	  new Array('user1Id','申请人未填写!'),
        	  new Array('user2Id','会议发起人未填写!'),
        	  new Array('user3Id','参会人员未填写!'),
        	  new Array('startDate','开始时间未填写!'),
        	  new Array('endDate','结束时间未填写!')
        	);
        	for(var i=0;i<arr.length;i++){
	        	if($("#"+arr[i][0]).val()==''){
	        	    $("#"+arr[i][0]).tips({
	  					side:3,
	  		            msg:arr[i][1],
	  		            bg:'#AE81FF',
	  		            time:1
	  		        });
	        		$("#"+arr[i][0]).focus();
	  				return;
	  			}
        	}
        	var agendas = $("#agenda").val();
        	if(agendas==""){
        		swal("请填写会议事项!");
        		return;
        	}
            $("#signupForm").ajaxSubmit({
                url: '<%=contextPath%>/meeting/add',
				type : 'post',
				dataType : "json",
				beforeSend: function () {
			        // 禁用按钮防止重复提交
					$("#sub").attr("disabled","disabled");
					swal("信息已经提交，请等待后台处理~！");
			    },
				success : function(data) {
					if (data.code == 200) {
						swal({
							title : data.message,
							type : "success",
							showCancelButton : false,
							confirmButtonText : "确定",
							animation : "slide-from-bottom",
							text: "2秒后自动关闭。", 
	      	    			timer: 2000, 
							closeOnConfirm : true
						}, function() {
							top.Dialog.close();
						});
					} else {
						swal("错误", data.message, "error");
					}  
				},    
				complete: function () {
			        $("#sub").removeAttr("disabled");
			    },
			    error: function (data) {
			    	swal("错误", data.message, "error");
			    }
			});
		});
	});
    
    //分配资源
	function openTree(obj,num){
	     var ids = $("#"+obj+num+"Id").val();
	     var type="";
	     if(num==1||num==2){
	    	 type = "redio";
	     }
	   	 var diag = new top.Dialog();
		 diag.Drag=true;
		 diag.Title ="请选择";
		 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids+'&types='+type;
		 diag.Width = 250;
		 diag.Height = 400;
		 diag.CancelEvent = function(){ //关闭事件
			 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
			 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
			if(tempid.length!==0){
				if(typeof(num)=="undefined"){ 
					$("#"+obj+"Id").val(tempid);
					$("#"+obj+"Name").val(tempname);
				}else{
					$("#"+obj+num+"Id").val(tempid);
					$("#"+obj+num+"Name").val(tempname);
				}
			}
			diag.close();
		 };
		 diag.show();
	}
	</script>
</body>
</html>